package com.lizhen.core.basicdatatype;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lizhen
 */
public class BasicDataType {

    static Map<String, Class<?>> baseToPackage = new HashMap<>();

    static {
        baseToPackage.put("byte", IConstBasicDataType.BYTE);
        baseToPackage.put("short", IConstBasicDataType.SHORT);
        baseToPackage.put("int", IConstBasicDataType.INTEGER);
        baseToPackage.put("long", IConstBasicDataType.LONG);
        baseToPackage.put("float", IConstBasicDataType.FLOAT);
        baseToPackage.put("double", IConstBasicDataType.DOUBLE);
        baseToPackage.put("char", IConstBasicDataType.CHARACTER);
        baseToPackage.put("boolean", IConstBasicDataType.BOOLEAN);
    }

    /**
     * @author lizhen
     */
    private static void ShowDataType(String clz) {
        String baseType = clz;
        long binaryBit = 0;
        Class<?> packageType = null;
        String minValue = "";
        String maxValue = "";
        packageType = baseToPackage.get(baseType);
        switch (baseType) {
            case "float":
                try {
                    binaryBit = packageType.getField("SIZE").getLong(packageType);
                    minValue = "" + packageType.getField("MIN_VALUE").getFloat(packageType);
                    maxValue = "" + packageType.getField("MAX_VALUE").getFloat(packageType);
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    e.printStackTrace();
                }
                break;
            case "double":
                try {
                    binaryBit = packageType.getField("SIZE").getLong(packageType);
                    minValue = "" + packageType.getField("MIN_VALUE").getDouble(packageType);
                    maxValue = "" + packageType.getField("MAX_VALUE").getDouble(packageType);
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    e.printStackTrace();
                }
                break;
            case "boolean":
                binaryBit = 2;
                minValue = "0";
                maxValue = "1";
                break;
            default:
                try {
                    binaryBit = packageType.getField("SIZE").getLong(packageType);
                    minValue = "" + packageType.getField("MIN_VALUE").getLong(packageType);
                    maxValue = "" + packageType.getField("MAX_VALUE").getLong(packageType);
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    e.printStackTrace();
                }
                break;
        }

        System.out.println("原始类：" + baseType);
        System.out.println("包装类：" + packageType.getCanonicalName());
        System.out.println("类数存储范围：" + binaryBit);
        System.out.println("最小值:" + minValue);
        System.out.println("最大值" + maxValue);
    }

    public static void baseAndWrappper() {
        Integer i1 = new Integer(100);
        int i2 = new Integer(100).intValue();
        int i22 = new Integer(100);
    }


    public static void main(String[] args) {
        ShowDataType("byte");
        ShowDataType("short");
        ShowDataType("int");
        ShowDataType("long");
        ShowDataType("float");
        ShowDataType("double");
        ShowDataType("char");
        ShowDataType("boolean");
        baseAndWrappper();
    }
}

